package code._17annotation._04handle;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;

public class Demo {
    public void m1() {
    }
    @Review
    public void m2() {
    }
    public void m3() {
    }

    public static void main(String[] args) throws ClassNotFoundException {
        //获取字节码文件对象
        Class<?> aClass = Class.forName("code._17annotation._04handle.Demo");
        //获取方法对象
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            boolean annotationPresent = declaredMethod.isAnnotationPresent(Review.class);
            if(annotationPresent){
                System.out.println(declaredMethod.getName()+" 使用了Review注解");
            }
        }
    }
}

//注意设置作用范围和作用位置
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface Review{
    String value() default "";
}
